<template>

</template>

<script>
    export default {
        name: "gaodeHotspot",
        computed: {
            //视图初始化状态监听
            viewerReadyEvent() {
                return this.$store.getters.gaodeMapStatus
            },
        },
        watch: {
            viewerReadyEvent(val) {
                if (window.gaodeMap || val) {
                    this.init()
                }
            }
        },
        methods: {
            init() {
                // 热点
                let infoWindow
                AMap.plugin([
                    'AMap.PlaceSearch',
                ], function () {
                    var placeSearch = new AMap.PlaceSearch();  //构造地点查询类
                    infoWindow = new AMap.InfoWindow({});
                    gaodeMap.on('hotspotover', function (result) {
                        placeSearch.getDetails(result.id, function (status, result) {
                            if (status === 'complete' && result.info === 'OK') {
                                placeSearch_CallBack(result);
                            }
                        });
                    });
                });

                //回调函数
                function placeSearch_CallBack(data) { //infoWindow.open(map, result.lnglat);
                    var poiArr = data.poiList.pois;
                    var location = poiArr[0].location;
                    infoWindow.setContent(createContent(poiArr[0]));
                    infoWindow.open(gaodeMap, location);
                }

                function createContent(poi) {  //信息窗体内容
                    var s = [];
                    s.push('<div class="info-title">' + poi.name + '</div><div class="info-content">' + "地址：" + poi.address);
                    s.push("电话：" + poi.tel);
                    s.push("类型：" + poi.type);
                    s.push('<div>');
                    return s.join("<br>");
                }
            }
        }
    }
</script>

<style scoped>

</style>
